//
//  SEOnlineReserveAllergyHistoryCell.swift
//  SmartEyeForPatient
//
//  Created by QDSG on 2021/4/6.
//

import UIKit

class SEOnlineReserveAllergyHistoryCell: UITableViewCell {
    
    private var endEditing: ((SEInquiryInfoViewModel) -> Void)?
    private var viewModel: SEInquiryInfoViewModel?
    
    override func awakeFromNib() {
        super.awakeFromNib()
        backgroundColor = UIColor.white
        contentView.backgroundColor = UIColor.white
    }

    func update(with viewModel: SEInquiryInfoViewModel, editEable: Bool = false, endEditing: ((SEInquiryInfoViewModel) -> Void)?) {
        self.viewModel = viewModel
        self.endEditing = endEditing
        textView.text = viewModel.info.allergicContent
        textView.isUserInteractionEnabled = !editEable ? viewModel.patientDidPicked : editEable
    }
    
    @IBOutlet private weak var textView: SETextView! {
        didSet {
            textView.placeholder = "请描述您的过敏史…"
            textView.tvDelegate = self
        }
    }
}

extension SEOnlineReserveAllergyHistoryCell: SETextViewDelegate {
    func textViewDidEndEditing(_ textView: UITextView) {
        guard let viewModel = viewModel else { return }
        viewModel.info.allergicContent = textView.text
        endEditing?(viewModel)
    }
}
